package cn.ilovese.collect.serviceimpl.screenshot;

import cn.ilovese.collect.datamapper.screenshot.ScreenshotMapper;
import cn.ilovese.collect.po.file.File;
import cn.ilovese.collect.po.screenshot.Screenshot;
import cn.ilovese.collect.service.screenshot.ScreenshotReportService;
import cn.ilovese.collect.util.Constant;
import cn.ilovese.collect.vo.ResultVO;
import cn.ilovese.collect.vo.file.FileVO;
import cn.ilovese.collect.vo.screenshot.ScreenshotVO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class ScreenshotReportServiceImpl implements ScreenshotReportService {
    @Resource
    ScreenshotMapper screenshotMapper;

    /**
     * 根据报告的id获取该报告对应的所有截图
     * @param reportId
     * @return
     */
    @Override
    public List<ScreenshotVO> getAllScreenshots(Integer reportId) {
        List<Screenshot> tempList = screenshotMapper.selectByReportId(reportId);
        List<ScreenshotVO> ret = new ArrayList<>();
        for(Screenshot screenshot: tempList){
            ret.add(new ScreenshotVO(screenshot));
        }
        return ret;
    }

    /**
     * 将一张截图对应的信息存入数据库
     * @param screenshotVO
     * @return
     */
    @Override
    public ResultVO<ScreenshotVO> createScreenshot(ScreenshotVO screenshotVO) {
        Screenshot screenshot=new Screenshot(screenshotVO);
        int id=screenshotMapper.insert(screenshot);
        if(id > 0){
            return new ResultVO<>(Constant.REQUEST_SUCCESS, "截图上传成功", new ScreenshotVO(screenshot));
        }
        return new ResultVO<>(Constant.REQUEST_FAIL, "截图上传失败");
    }


    // @Resource标识特定的目标组件，你们自己添加，类似软工二
    // @Autowired装载java bean，用于set方法，你们自己添加，类似软工二
    //注意在这里添加每个实现方法的说明注释，类似以下
    /**
     * 这个方法干了什么
     *
     * @param 参数1 解释
     * @param 参数2 解释
     * ......
     * @return 返回值解释
     */
}
